-
Notifications
You must be signed in to change notification settings - Fork 13.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(db): use paginated_update for viz migration #20761
Conversation
c63933b
to
f70a6fe
Compare
0f8233c
to
7484f25
Compare
7484f25
to
b67a49f
Compare
@@ -45,11 +63,11 @@ def _migrate(self) -> None: | |||
|
|||
rv_data = {} | |||
for key, value in self.data.items(): | |||
if key in self.mapping_keys and self.mapping_keys[key] in rv_data: | |||
if key in self.rename_keys and self.rename_keys[key] in rv_data: | |||
raise ValueError("Duplicate key in target viz") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we should raise an error here. Maybe just silently override?
source_viz_type: str | ||
target_viz_type: str | ||
|
||
def __init__(self, form_data: str) -> None: | ||
self.data = json.loads(form_data) | ||
self.data = try_load_json(form_data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Data may be corrupted, let's always try/catch just to be safe.
class MigrateVizEnum(str, Enum): | ||
# the Enum member name is viz_type in database | ||
treemap = "treemap" | ||
area = "area" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not need for such enum since we will import different stuff for different migrations anyway.
Codecov Report
@@ Coverage Diff @@
## master #20761 +/- ##
===========================================
- Coverage 66.35% 54.62% -11.74%
===========================================
Files 1754 1756 +2
Lines 66689 66721 +32
Branches 7049 7049
===========================================
- Hits 44253 36446 -7807
- Misses 20639 28478 +7839
Partials 1797 1797
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for improving migration in the production environment. LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for the fix and detailed context @ktmud!
SUMMARY
DB migration introduced by #20359 did not run through in Airbnb environment and throws this error for our MySQL database:
This is because updating objects within
iter_per
does not work with MySQL cursors. I guess the MySQL client just doesn't like writing while reading. (Maybe other databases will have similar issues if anyone with more than 1,000 area charts can test?)We've seen this error before, which was why
paginated_update
was introduced. Instead of streaming results with cursors,paginated_update
which runs manual pagination withOFFSET
andLIMIT
, which makes sure read and write operations happen independently.While optimizing this, I also did some other refactoring for the migration_viz class. Most notably, I relocated the files (and the corresponding tests) from superset root to
superset.migrations
as migration code should be as self-contained and as stable as possible. Anything under the root directory is considered app code, and app code can be updated much more frequently.While testing, I also noticed that some charts will fail at reloading
query_context
as the combined JSON payload is too large for a default Text column in MySQL (which has max size of 64kb). Theupgrade
was not able to save the full serialized JSON string---thendowngrade
would fail. We need to migrate bothSlice.query_context
andSlice.params
toMediumText
, which I will address in another PR.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A
TESTING INSTRUCTIONS
CI and tested locally with Airbnb db instances.
The area chart migration was finished in ~20 seconds for about
ADDITIONAL INFORMATION